/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AIproccess;

import Army.building.Building;
import Army.building.BuildingBarrack;
import Army.building.BuildingHouse;
import Army.building.BuildingMine;
import Army.ComputerTeam;
import Army.PlayerTeam;
import GameObject.LayerManager;

/**
 *
 * @author Huy
 */
public class PlayerAIDevelopeNoob extends PlayerAIDevelope {

	public PlayerAIDevelopeNoob(LayerManager layer, ComputerTeam team) {
		super(layer, team);
		delay = 1000;
	}

	@Override
	protected void proccess() {
		int maxi = 0;
		int max = -1;
		for (int i = 0; i < 8; i++) {
			int newMax = develope(i);
			if (max < newMax) {
				maxi = i;
				max = newMax;
			}
		}
		Building building = null;
		switch (maxi) {
			case 0: {
				team.createNewUnit("worker", getCastle(team));
				break;
			}
			case 1: {

				building = new BuildingMine(team.getTeamId());
				building.setPosition(getPosition(team, 200));

				break;
			}
			case 3: {
				building = new BuildingBarrack(team.getTeamId());
				building.setPosition(getPosition(team, 400));
				break;
			}
			case 4: {
				Building barrack = getBarrack(team);
				if (barrack == null) {
					break;
				}
				if (RANDOM.nextDouble() > 0.5) {
					team.createNewUnit("swordman",barrack);
				} else {
					team.createNewUnit("spearman",barrack);
				}
				break;
			}
			case 5: {
				Building barrack = getBarrack(team);
				if (barrack == null) {
					break;
				}
				team.createNewUnit("archer",barrack);
				break;
			}
			case 6: {
				building = new BuildingHouse(team.getTeamId());
				building.setPosition(getPosition(team, 200));
				break;
			}
			case 7: {
			}
			default:
				return;
		}
		if (building != null && !team.getWorkerGroup().getListUnit().isEmpty()
				&& team.getWorkerGroup().getListUnit().get(0).isTaskCompleted()) {
			fixPosition(building);
			if (layer.isBuildAble(building) && team.add(building)) {
				building.startBuild();
				team.getWorkerGroup().setTarget(building);
			}

		}
	}

	public int develope(int i) {
		
		int point = 0;

		int n = Math.min(team.getGold(), 2000);

		switch (i) {
			case 0: {
				if (team.getWorkerGroup().isEmpty()) {
					point = 2000 - team.getnBarrack() * 10 - team.getnMine() * 50 + RANDOM.nextInt(100);
				} else if (team.getWorkerGroup().size() < 2) {
					point = 800 + RANDOM.nextInt(100);
				} else {
					point = 400 - 100 * team.getWorkerGroup().size() + RANDOM.nextInt(100);
				}
				break;
			}
			case 1: {
				if (team.getnMine() < 10) {
					point = 1000 - team.getnMine() * 10 - n / 5 + RANDOM.nextInt(100);
				} else {
					point = 800 - team.getnMine() * 20 - n / 2 + RANDOM.nextInt(100);
				}
				break;
			}
			case 3: {
				point = n - team.getnBarrack() * 300 + RANDOM.nextInt(100);
				break;
			}
			case 4: {
				if (team.getnBarrack() > 0) {
					point = n / 3 + (team.getPopulationLimit() - team.getPopulation()) * 100
							+ RANDOM.nextInt(100);
				} else {
					point = 0;
				}
				break;
			}
			case 5: {
				if (team.getnBarrack() > 0) {
					point = n / 3 + (team.getPopulationLimit() - team.getPopulation()) * 100
							+ RANDOM.nextInt(100);
				} else {
					point = 0;
				}
				break;
			}
			case 6: {
				if (team.getPopulationLimit() < PlayerTeam.LIMIT) {

					point = team.getnBarrack() * 300 + n / 2
							- (team.getPopulationLimit() - team.getPopulation()) + RANDOM.nextInt(100);
				} else {
					point = 0;
				}
				break;
			}
			case 7: {

				break;
			}
			default:
				point = 300 + n / 10 - team.getnBarrack() * 1000 + RANDOM.nextInt(100);
			//return null;
		}
		/*if (Math.random() < 0.2) {
		 buildposition.building = getCastle(team);
		 buildposition.unit = new UnitWorker(team.getTeamId());
		 buildposition.point = (int) (900 - 10 * team.getWorkerGroup().size() + Math.random() * 100);
		 }
		 if (team.getGold() > BuildingBarrack.BUILD_COST) {
		 }*/
		return point;
	}
}
